package allTests;

import com.supermap.desktop.core.Application;
import org.junit.runner.JUnitCore;
import org.junit.runner.Request;
import org.junit.runner.Result;

/**
 * Created by hanyz on 2016/8/30.
 */
public class StartThread extends Thread{
    /*直接在调用JUnitCore.run会抛异常：
    allTests.TestComponent Only on the event dispatch thread
    java.lang.IllegalThreadStateException: Only on the event dispatch thread*/
    public void run(){

        /*Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
            @Override
            public void eventDispatched(AWTEvent event) {
                System.out.println(event);
                if(event instanceof PaintEvent){
                    PaintEvent paintEvent = (PaintEvent) event;
                    System.out.println(paintEvent.getID());
                    System.out.println(paintEvent.getSource());
                    final DateFormat format = new SimpleDateFormat("HH:mm:ss");
                    String date = format.format(new Date());
                    System.out.println("[" + date + "] "+ event.getID());	}
            }
        }, AWTEvent.PAINT_EVENT_MASK);*/

        Application.getActiveApplication().getOutput().output("JUnit Tests start..");
        Class c = null;
        try {
            c = Class.forName("allTests.TestVectorAnalyst");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Result result = new JUnitCore().run(Request.method(c,"testBufferAnalyst_Point"));
        if(result.getFailures()!=null &&result.getFailures().size()>0){
            System.out.println(result.getFailures().get(0).getTrace());
        }
        System.out.println(result);
    }
}
